﻿using System.Collections.Generic;
using System;



namespace Framework
{
    public delegate void NetDataListener(NetData msg);
    public class NetDataListenerMgr 
	{
		private static List<NetDataListener> _listeners = new List<NetDataListener>(256);
        public static void RegisterMsgListener(short sub, NetDataListener listener)
        {
            while (_listeners.Count <= sub)
            {
                _listeners.Add(null);
            }
            if (_listeners[sub] != null && _listeners[sub] != listener)
            {
                UnityEngine.Debug.Log(string.Format("NetMessageListener Duplicat error: old:{0},new:{1}", _listeners[sub].Method.Name, listener.Method.Name));
            }
            _listeners[sub] = listener;
        }


        public static void UnRegisterMsgListener(short sub, NetDataListener listener)
        {

            _listeners[sub] = null;
        }

        public static NetDataListener GetListener( short subid)
        {
          
            if (_listeners.Count <= subid)
            {
                return null;
            }
            return _listeners[subid];
        }

    }



}
